package com.moore.utils;

import java.util.HashMap;
import java.util.Map;

public class WebUtils {

    // 解析url参数
    public static Map<String, String> getParams(String url) {
        Map<String, String> params = new HashMap<>();
        if (url.contains("?")) {
            String[] urlParts = url.split("\\?");
            String[] paramParts = urlParts[1].split("&");
            for (String paramPart : paramParts) {
                String[] keyValue = paramPart.split("=");
                String key = keyValue[0];
                if (keyValue.length == 2) {
                    String value = keyValue[1];
                    params.put(key, value);
                } else {
                    params.put(key, null);
                }
            }
        }
        return params;
    }

    // 获取MIME类型
    public static Map<String, String> getMimeTypes() {
        // 创建mimeTypes映射存储文件扩展名和MIME类型的对应关系
        Map<String, String> mimeTypes = new HashMap<>();
        // 将文件扩展名和MIME类型添加到映射中
        mimeTypes.put("html", "text/html");
        mimeTypes.put("css", "text/css");
        mimeTypes.put("js", "application/javascript");
        mimeTypes.put("png", "image/png");
        mimeTypes.put("jpg", "image/jpeg");
        mimeTypes.put("jpeg", "image/jpeg");
        mimeTypes.put("gif", "image/gif");
        mimeTypes.put("ico", "image/x-icon");
        mimeTypes.put("ttf", "application/x-font-ttf");
        mimeTypes.put("mp3", "audio/mpeg");
        mimeTypes.put("mp4", "video/mp4");
        return mimeTypes;
    }
}
